#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 21 23:06:28 2023

@author: liqingsimac
"""

import numpy as np

mydata=np.genfromtxt('sports_enrollment.csv',delimiter=',')

#去掉第一行项目编号、第一列运动员编号
A=mydata[1:,1:]

#将nan转化为零
B=np.nan_to_num(A)

#计算邻接矩阵
C=B.T
D=C@B

#保存为整数型
F=np.zeros([14,14],dtype=int)
for k in range(14):
    for m in range(14):
        F[k,m]=int(D[k,m])

##随机搜索法
BestR=np.array(range(14))
BestS=100
for t in range(200000):
    R=np.random.permutation(14)
    S=0
    for k in range(13):
        S=S+F[R[k],R[k+1]]
    if S<BestS:
        BestS=S
        BestR=R
print(BestR)
print(BestS)


